//
//  ReadingMaskingView.m
//  Cbchot
//
//  Created by 王欣 on 2018/1/3.
//  Copyright © 2018年 王越. All rights reserved.
//

#import "CBCReadingMaskingView.h"
#import "CBCReaderDef.h"
#import "CommonFuctions.h"
#if __has_include(<Masonry/Masonry.h>)
#import <Masonry/Masonry.h>
#else
#import "Masonry.h"
#endif
@interface CBCReadingMaskingView()
@property(nonatomic,strong)UIImageView * centerImg;
@property(nonatomic,strong)UIImageView * topImg;
@property(nonatomic,strong)UIImageView * bottomImg;
@end
@implementation CBCReadingMaskingView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {

        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.9];

        [self setupUI];
    }return self;
}

-(void)setupUI{
    
    UIImage * center = [CommonFuctions cbcReaderImage:@"readGuideCenter"];

    UIImage * top = [[CommonFuctions cbcReaderImage:@"readGuideLine"] resizableImageWithCapInsets:UIEdgeInsetsMake(92, 0, 92, 0) resizingMode:(UIImageResizingModeStretch)];
    self.centerImg.image = center;
    self.topImg.image = top;
    self.bottomImg.image = top;
    [self addSubview:self.centerImg];
    [self addSubview:self.topImg];
    [self addSubview:self.bottomImg];
    [self.centerImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    [self.topImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.centerX.equalTo(self);
        make.width.equalTo(@1);
        make.bottom.equalTo(self.centerImg.mas_top);
    }];
    [self.bottomImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self);
        make.centerX.equalTo(self);
        make.width.equalTo(@1);
        make.top.equalTo(self.centerImg.mas_bottom);
    }];
    
}

//显示
-(void)show{
    
    UIView * view = [UIApplication sharedApplication].keyWindow;
    [view addSubview:self];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self removeFromSuperview];
}
//隐藏
-(void)hide{
    
    [self removeFromSuperview];

}

-(UIImageView *)centerImg{
    if (!_centerImg) {
        _centerImg = [[UIImageView alloc]init];
        _centerImg.contentMode = UIViewContentModeScaleAspectFill;
    }return _centerImg;
}
-(UIImageView *)topImg{
    if (!_topImg) {
        _topImg = [[UIImageView alloc]init];
        _topImg.contentMode = UIViewContentModeScaleAspectFill;
    }return _topImg;
}
-(UIImageView *)bottomImg{
    if (!_bottomImg) {
        _bottomImg = [[UIImageView alloc]init];
        _bottomImg.contentMode = UIViewContentModeScaleAspectFit;
    }return _bottomImg;
}
@end
